#define LOG_TAG "JNIAdblock"

#include "jni.h"
#include <string>
#include <mujs.h>

#include <android/log.h>

static void hello(js_State *J)
{
    const char *name = js_tostring(J, 1);
    // printf("Hello, %s!\n", name);
    __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "xiangjt Hello, %s!\n", name); 
    js_pushundefined(J);
}

static void test(JNIEnv* env, jobject obj, jstring str)
{
    js_State *J = js_newstate(NULL, NULL, JS_STRICT);

    js_newcfunction(J, hello, "hello", 1);
    js_setglobal(J, "hello");

    js_dostring(J, "hello('world');");

    js_freestate(J);
}

static JNINativeMethod methods[] =
{
    { "test", "(Ljava/lang/String;)V", (void*)test },
};

extern "C" JNIEXPORT void JNICALL Java_com_sample_mujstest_MujsTest_registerNatives(JNIEnv *env, jclass clazz)
{
  env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
}

